<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ include file="../include.inc.jsp" %>
<html>
<head>
    <title></title>
    <link href="${ctx}/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/lib/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
    
    <link href="${ctx}/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/common/style.css" rel="stylesheet" type="text/css" />
    <script src="${ctx}/common/common.js" type="text/javascript"></script>
    
    <script src="${ctx}/lib/jquery/jquery-1.9.0.min.js" type="text/javascript"></script>
    <script src="${ctx}/lib/ligerUI/js/ligerui.all.js" type="text/javascript"></script>
    <script type="text/javascript">
    var customer=parent.customer;
    $(document).ready(function(){
    	//为客户信息赋值
    	$('#cId').val(customer.cId);
    	$('#cName').text(customer.cName);

 
    	/* $('#cAddress').text(customer.cAddress); */
    	
    	var jsons='${sale}';
    	if(jsons!=''){
    		jsons=$.parseJSON(jsons);
    		loadTOForm(jsons,"form");
    	}
    });
    
    function save(){
    	var cId=$("#selectCName option:selected").attr("value");
    	$("#cId").val(cId);
    	$.post('${ctx}/saleGold/save',formToJson('form'),function(data){
    		if(data.success){
    			$.ligerDialog.success(data.msg);
    			parent.$.ligerDialog.close();
    			parent.$.ligerDialog.success(data.msg);
    		}else{
    			$.ligerDialog.success(data.msg);
    		}
    	});
    }
    
    function setSgCost(){
    	var pWight=parseInt($('#sgWeight').val());
    	var sgPrice=parseFloat($('#sgPrice').val()).toFixed(4);
    	var total=(pWight*sgPrice).toFixed(4);
    	if(total>0)
    		$('#sgCost').val((pWight*sgPrice).toFixed(4));
    }
    
    </script>
</head>
<body style="overflow-x:hidden">
<div class="container">
	<div style="padding:10px">
		<form class="form_style" id="form">
			<input type="hidden" id="cId" name="cId">
			<input type="hidden" id="sgId" name="sgId">
			<input type="hidden" id="sgState" name="sgState">
			<ul>
				<!-- <li><div style='width:350px'>客户姓名：<span style="width:300px" id='cName'></span></div></li> -->
				<li>客户姓名:<c:if test="${operator==1}">
				<select name="cName" id="selectCName" disabled="disabled">
							<option value='1'>请选择</option>
							<c:if test="${null!=customers}">
                            <c:forEach var ="customer" items="${customers}">
                            <c:if test="${cId==customer.cId}">
                            	<option  selected="selected" value="<c:out value='${customer.cId}'/>"><c:out value='${customer.cName}'/></option>
                            </c:if>
	                        <c:if test="${cId!=customer.cId}">
                            	<option value="<c:out value='${customer.cId}'/>"><c:out value='${customer.cName}'/></option>
                            </c:if>
                            </c:forEach>
                        	</c:if>
						</select>
							</c:if>
							<c:if test="${operator==0}">
				<select name="cName" id="selectCName" >
							<option value='1'>请选择</option>
							<c:if test="${null!=customers}">
                            <c:forEach var ="customer" items="${customers}">
                            <c:if test="${cId==customer.cId}">
                            	<option  selected="selected" value="<c:out value='${customer.cId}'/>"><c:out value='${customer.cName}'/></option>
                            </c:if>
	                        <c:if test="${cId!=customer.cId}">
                            	<option value="<c:out value='${customer.cId}'/>"><c:out value='${customer.cName}'/></option>
                            </c:if>
                            </c:forEach>
                        	</c:if>
						</select>
							</c:if>
				</li>
				<!-- <li><div style='width:350px'>客户地址：<span id='cAddress'></span></div></li> -->
				<li>收购单号：<input readonly="readonly" type="text" name="sgNumber" value="${sgNumber}"></li>
				<li>收购黄金：<select  name="gId">
							<option value='1'>请选择</option>
							<c:if test="${null!=golds}">
                            <c:forEach var ="gold" items="${golds}">
                                <option value="<c:out value='${gold.gId}'/>"><c:out value='${gold.gName}'/></option>
                            </c:forEach>
                        	</c:if>
						</select>
				</li>
				<li>总&nbsp;重&nbsp;量：<input onblur="setSgCost()" id="sgWeight" type="text" name="sgWeight"></li>
				<li>单价/g：<input onblur="setSgCost()" id='sgPrice' type="text" name="sgPrice"></li>
				<li>付款金额：<input readonly="readonly" id="sgCost" type="text" name="sgCost"></li>
				<li>实付金额：<input type="text" name="sgPay"></li>
			</ul>
		</form>
	</div>
	
	<div id="maingrid"></div>
	<h5>
		<button onclick="save()" type="button" class="btn btn-primary">保存</button>
		<button onclick="document.getElementById('form').reset()" type="button" class="btn btn-primary">重置</button>
	</h5>	
</div>

</body>
</html>
